package com.biz.hunter.dao;

import java.util.List;

import com.biz.hunter.db.entity.Employee;
import com.biz.hunter.db.entity.Person;
import org.springframework.stereotype.Repository;

import com.biz.hunter.db.entity.City;
import com.biz.hunter.dbutil.BaseDAO;


@Repository
public class CityDAO {
	private static final String SQL_GET_ID = "select * from tb_city  where id = ?";
	private static final String SQL_GET_NAME = "select * from tb_city  where Name = ?";
	private static final String SQL_GET_ALL = "select * from tb_city ";
	
	
	public List<City> getALL() {

		return BaseDAO.queryForList(City.class, SQL_GET_ALL);

	}
	
	
	
	public City getById(int Id) {
		return  BaseDAO.queryForObject(City.class, SQL_GET_ID, Id);
	}
	public City getByName(String name){
		return  BaseDAO.queryForObject(City.class, SQL_GET_NAME, name);
	}



	protected static final String SQL_UPDATE_PROFILE = "update tb_person "
			+ " set  name=? ,  workage=?, bestdomain=? ,   "
			+ "companyId=?, companyname=?, cityId=?,cityName= ?,"
			+ " roleId=?, roleName=? , platformid=?,  domainId= ? , domainName=? ,image=? where id =?";

	public int updateProfile1(Person person) {
		System.out.println("dao11111111111");
		int execute = BaseDAO.execute(SQL_UPDATE_PROFILE, person.getName(),
				0, person.getBestdomain(),
				person.getCompanyId(), person.getCompanyName(), person.getCityId(),
				person.getCityName(), person.getRoleId(), person.getRoleName(),
				person.getPlatformId(), person.getDomainId(), person.getDomainName(), person.getImage(),
				person.getId());
		System.out.println("[updateProfile SQL]: "+SQL_UPDATE_PROFILE+"  rows:"+execute);
		return execute;
	}

	String UPDATE_EMP_domain  = "update tb_employee "
			+ "set domainId=?, domainName =? , headimgurl = ?  where personId =?";

	public void updateDomain(Employee emp) {
		int result = BaseDAO.execute(UPDATE_EMP_domain,  emp.getDomainId(),emp.getDomainName(),
				emp.getHeadImgUrl(),
				emp.getId());
		System.out.println("[updateDomain SQL]: "+UPDATE_EMP_domain+" rows:"+result);

	}

	private static final String UPDATE_EMP_PROFILE = "update tb_employee "
			+ "set expectJob=?, expectJobName=?, expectCompany1=?, expectCompanyName1 = ? ,expectCompany2=?,expectCompanyName2 = ? ,"
			+ "expectCompany3=?, expectCompanyName3 = ? , intentTime=?,"
			+ " registed =?,comment=? ,state=? ,jobName=?" + ",majorDomainId1 = ? ,"
			+ "majorDomainId2=? ,"
			+ "majorDomainId3=?  where personId =?";

	public int updateProfile(Employee emp) {
		if (emp == null) {
			return -1;
		}

		int result = BaseDAO.execute(UPDATE_EMP_PROFILE, emp.getExpectJob(), emp.getExpectJobName(), emp.getExpectCompany1(), emp.getExpectCompanyName1(),
				emp.getExpectCompany2(), emp.getExpectCompanyName2(),emp.getExpectCompany3(),
				emp.getExpectCompanyName3(), emp.getIntentTime(),
				emp.getCompleted(),
				emp.getComment(), emp.getState(),emp.getRoleName(),
				emp.getMajorDomainId1(),emp.getMajorDomainId2(),
				emp.getMajorDomainId3(),emp.getId());
		System.out.println("[updateProfile SQL]: "+UPDATE_EMP_PROFILE+" rows:"+result);
		return result;
	}
}
